<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Vote\Controller;

use Think\Controller;

class TestController extends Controller {

    function index() {
        
        $error = array(
            0=>array('email'=>'1777@qq.com','phone'=>135551,'idcard'=>11111),
            1=>array('email'=>'','phone'=>'','idcard'=>11112),
            2=>array('email'=>'3777@qq.com','phone'=>135553,'idcard'=>11113),
            //3=>array('email'=>'4777@qq.com','phone'=>135554,'idcard'=>11114),
            
        );
        foreach ($error as $key => $value) {
            $where['idcard'] = $value['idcard'];
            $zinfo['email'] = $value['email'];
            $zinfo['phone'] = $value['phone'];
            M('fff')->where($where)->save($zinfo);
            
            $eArr[$value['idcard']] = $error[$key];
            $idcards .=  $value['idcard'].',';
        }
        exit;
        $where['idcard'] = array('in',ltrim($idcards,','));
        $list = M('fff')->where($where)->select();
        //print_r($list);exit;
        foreach ($list as $key => $value) {
            
        }
        
        
        
        exit;
        
        
         header("Content-type: text/html; charset=utf-8");   
         $rs = check_vip($_GET['openid']);
         echo 'name:'.$rs['huiyuan_name'];
         echo '<br>';
         echo 'tel:'.$rs['huiyuan_tel'];
         return;
        // print_r( check_vip($_GET['card_no']));
         //addCredits($_GET['card_no'], 200000);
        //echo updateCardNoByPhone('18501532546','66006609');
        echo '<br>';
        echo '充值会员卡号:'.$_GET['card_no'];
		echo '<br>';
		echo '会员原始积分为:'. getCredits($_GET['card_no']);
		echo '<br>';
                exit;
         if($_GET['openid_cfh']) {
            $_SESSION['openid_cfh']=$_GET['openid_cfh'];
        }
        if(!$_SESSION['openid_cfh']) {
            $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
            $url_param = str_replace( array("/","+","="), array(":","|",";"), base64_encode($url) );
            redirect("http://cfh.changfaproperties.com/api/owner/getopenid/".$url_param);
        }
        
        echo $_SESSION['openid_cfh'];exit;
        
        
        
        
        
        echo wx_openid();exit;
        $bool = R('Api/Fans/updateFansByOpenid',array(wx_openid()));
       
        if ($bool === true) {
           echo 111;
            // $redirec_url = 'http://a.forcent.cn/ldh/store.php/Member/requestQrcode/' . $url;
            // redirect('http://a.forcent.cn/iHuiyuan/user/Integral?url=' . ($redirec_url));
        } else {
            redirect('http://mp.weixin.qq.com/s?biz=MjM5ODg1MDI2OA==&mid=209800739&idx=1&sn=54b350a36b6655303eadca02c425ddb9#rd');
        }
    }

	function cgibin_wxopenid($next_openid=null){
		$url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=RfSVPG3_bGop01KO5WlZXiWlKWnzlVz80PZV5yaDVuWV_MqzNWc1fU6diR_PXfkA-pGiPjgLq7rXyOuf-saAAsLrK8VULdh4y5yqmoFrCKMXNBdAJAMCQ&next_openid=".$next_openid ;
            $data = http_get($url);
            $openlist = json_decode($data, true);
			//$openidArr = $openlist['data']['openid'];
			return $openlist;
		
	}
    function aa($openid =null) {
        set_time_limit(0);
        $data = S('opencache' . $openid);
        if (empty($data)) {
            $dbdata = M('openid')->select();
            foreach ($dbdata as $key => $value) {
                $arr[] = $value['openid'];
            }
            $openlist = $this->cgibin_wxopenid();
			//echo $openlist['total'];exit;
			$openidArr = $openlist['data']['openid'];
			if($openlist['total'] > 10000){
				//echo array_slice($openidArr,-1,1)[0];exit;
				$list = $this->cgibin_wxopenid(array_slice($openidArr,-1,1)[0]);
				$openidArr2 = $list['data']['openid'];
				
			}
			$last = array_merge($openidArr,$openidArr2);
			//echo count($last);
			print_r($last);
			exit;
			//print_r($openlist);exit;
            
			print_r( array_slice($openidArr,-1,1));exit;
            //print_r($openidArr);exit;
            $c = array_intersect($openidArr, $arr);
            $b = array_diff($openidArr, $arr);
            $d = array_merge(array_diff($openidArr, $arr));
            // print_r($d);  echo count($openidArr);exit;

            $datalist = array();
            echo '<br>';
            echo count($b);
            print_r($b);
            echo '<br>';
            echo count($c);
            //   print_r($c);
            echo '<br>';
            // print_r($openidArr);
            echo count($openidArr);
            foreach ($b as $key => $value) {
                $datalist[] = array('openid' => $b[$key]);
            }
            //print_r($datalist);
            M('Openid')->addAll($datalist);
            S('opencache' . $openid, $openid, 3600 * 4);
            //exit;
        }
    }

}
